﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using QuanLyVanBanBUS;

public partial class QLVB_Admin_CapNhatChucVu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Page.IsPostBack == false)
        {
            layMaChucVu();

            layTenChucVu();
        }
    }

    protected void layMaChucVu()
    {
        string maChucVuURL = Request.QueryString["MaChucVu"];

        ChucVuBUS cvBUS = new ChucVuBUS();

        string maChucVu = cvBUS.layMaChucVu(maChucVuURL);

        txtMaChucVu.Text = maChucVu;
    }

    protected void layTenChucVu()
    {
        string maChucVuURL = Request.QueryString["MaChucVu"];

        ChucVuBUS cvBUS = new ChucVuBUS();

        string tenChucVu = cvBUS.layTenChucVu(maChucVuURL);

        txtTenChucVu.Text = tenChucVu;
    }

    protected void btnCapNhat_Click(object sender, EventArgs e)
    {
        {
            ChucVu cvDTO = new ChucVu();
            cvDTO.MaChucVu = txtMaChucVu.Text.ToUpper();
            cvDTO.TenChucVu = txtTenChucVu.Text.ToUpper();

            //Kiem tra rong
            if (cvDTO.MaChucVu.ToString() == string.Empty)
            {
                Alert.Show("Ma chuc vu khong duoc rong");
                return;
            }

            if (cvDTO.TenChucVu.ToString() == string.Empty)
            {
                Alert.Show("Ten chuc vu khong duoc rong");
                return;
            }

            //Sua
            if (cvDTO.MaChucVu.ToString() != string.Empty && cvDTO.TenChucVu.ToString() != string.Empty)
            {
                ChucVuBUS cvBUS = new ChucVuBUS();

                string maChucVuURL = Request.QueryString["MaChucVu"];

                cvBUS.suaChucVu(cvDTO, maChucVuURL);

                Response.Redirect("ThamSoNguoiDung.aspx");
            }
        }
    }

    protected void btnDong_Click(object sender, EventArgs e)
    {
        Response.Redirect("ThamSoNguoiDung.aspx");
    }
}